package com.zggk.iroad.diease.dieasemx;


import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zggk.iroad.R;
import com.zggk.iroad.db.EntityManager;
import com.zggk.iroad.db.LxInfo;
import com.zggk.iroad.greendao.LxInfoDao;
import com.zggk.iroad.mvp.MVPBaseActivity;
import com.zggk.iroad.util.MyUtils;
import com.zggk.iroad.util.NoScroolGridView;
import com.zggk.iroad.util.ShowGridAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;


/**
 * MVPPlugin
 * 邮箱 784787081@qq.com
 */

public class DieaseMxActivity extends MVPBaseActivity<DieaseMxContract.View, DieaseMxPresenter> implements DieaseMxContract.View {

    @Bind(R.id.back)
    ImageView back;
    @Bind(R.id.title_text)
    TextView titleText;
    @Bind(R.id.cancle_button)
    TextView cancleButton;
    @Bind(R.id.xcry_te)
    TextView xcryTe;
    @Bind(R.id.xcry_lay)
    LinearLayout xcryLay;
    @Bind(R.id.lx_te)
    TextView lxTe;
    @Bind(R.id.lx_lay)
    LinearLayout lxLay;
    @Bind(R.id.xcsj_te)
    TextView xcsjTe;
    @Bind(R.id.xcsj_lay)
    LinearLayout xcsjLay;
    @Bind(R.id.szh_k)
    TextView szhK;
    @Bind(R.id.szh_lay)
    LinearLayout szhLay;
    @Bind(R.id.tzh_k)
    TextView tzhK;
    @Bind(R.id.tzh_lay)
    LinearLayout tzhLay;
    @Bind(R.id.disease_shang_txt)
    TextView diseaseShangTxt;
    @Bind(R.id.xsfx_lay)
    LinearLayout xsfxLay;
    @Bind(R.id.bhlx_te)
    TextView bhlxTe;
    @Bind(R.id.bhlx_lay)
    LinearLayout bhlxLay;
    @Bind(R.id.bhmc_te)
    TextView bhmcTe;
    @Bind(R.id.bhmc_lay)
    LinearLayout bhmcLay;
    @Bind(R.id.bhsl_te)
    TextView bhslTe;
    @Bind(R.id.bhsl_lay)
    LinearLayout bhslLay;
    @Bind(R.id.bz_lay)
    LinearLayout bzLay;
    @Bind(R.id.bz_et)
    TextView bzEt;
    @Bind(R.id.tjtp_lay)
    LinearLayout tjtpLay;
    @Bind(R.id.add_pic_grid)
    NoScroolGridView addPicGrid;
    @Bind(R.id.add_pic_lay)
    LinearLayout addPicLay;
    private LxInfoDao lxInfoDao;

    @Override
    public void onRequestError(String msg) {

    }

    @Override
    protected int getLayout() {
        return R.layout.act_diease_mx;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        initView();
        initData();
    }

    private void initData() {
        lxInfoDao = EntityManager.getInstance().getLxInfoDao();
        mPresenter.testinfo(DieaseMxActivity.this, getIntent().getStringExtra("RZID"));
    }

    private void initView() {
        titleText.setText("病害明细");
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    @Override
    public void getData(DieaseMxBean videoVos2) {
        List<LxInfo> SSS = lxInfoDao.queryBuilder().where(LxInfoDao.Properties.LXMC.eq(videoVos2.getBHDATA().get(0).getLXMC())).limit(1).list();
        xcryTe.setText(videoVos2.getBHDATA().get(0).getDCR());
        lxTe.setText(SSS.get(0).getLXMC());
        xcsjTe.setText(videoVos2.getBHDATA().get(0).getDCSJ());
        String qdzh = videoVos2.getBHDATA().get(0).getQDZH();
        szhK.setText(MyUtils.getZHMCByZH(qdzh));
        String tjqdzh = videoVos2.getBHDATA().get(0).getTJQDZH();
        tzhK.setText(MyUtils.getZHMCByZH(tjqdzh));
        diseaseShangTxt.setText(videoVos2.getBHDATA().get(0).getWZFX());
        bhlxTe.setText(videoVos2.getBHDATA().get(0).getSHBW());
        bhmcTe.setText(videoVos2.getBHDATA().get(0).getBHMC());
        bhslTe.setText(videoVos2.getBHDATA().get(0).getYGSL());
        bzEt.setText(videoVos2.getBHDATA().get(0).getBZ());
        ArrayList<String> listImgUrl = new ArrayList<>();
        if (videoVos2.getTPDZ() != null && videoVos2.getTPDZ().size() > 0) {
            for (int i = 0; i < videoVos2.getTPDZ().size(); i++) {
                listImgUrl.add(videoVos2.getTPDZ().get(i).getFILEPATH());
            }
        }
        ShowGridAdapter showGridAdapter = new ShowGridAdapter(this, listImgUrl);
        addPicGrid.setAdapter(showGridAdapter);
    }
}
